import requests,base64
import os
class Code:
    def __init__(self) -> None:
        pass

    def getCodes(self,n):
        for i in range(n):
            r=requests.get("http://192.168.0.1:8080/auth/api/v1/common/captcha")
            base64Str=r.json()['data']['captcha'][22:]
            imgdata=base64.b64decode(base64Str)
            fileName=os.path.join(os.path.dirname(__file__),'sourceImg','code{}.png'.format(i+1))
            file=open(fileName,'wb')
            file.write(imgdata)
        file.close()
    def base64_to_image(self,base64Str):
        base64Str=base64Str[22:]
        imgdata=base64.b64decode(base64Str)
        fileName=os.path.join(os.path.dirname(__file__),'sourceImg','code_test.png')
        file=open(fileName,'wb')
        file.write(imgdata)
        file.close()

if __name__=='__main__':
    code=Code()
    code.getCodes(300)
